Skip to content

Fix duplicate logging of MsalUiRequiredException (in-repo copy of #3910)#3941

Merged
iarekk merged 2 commits into
masterfrom
iarekk/pr-3910-duplicate-msaluirequired-log
Jul 13, 2026
Merged

Fix duplicate logging of MsalUiRequiredException (in-repo copy of #3910)#3941
iarekk merged 2 commits into
masterfrom
iarekk/pr-3910-duplicate-msaluirequired-log

Conversation

@iarekk

@iarekk iarekk commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

In-repo copy of #3910 by @armin-azar, opened so the azure-pipelines app runs the PR pipeline natively (fork PRs don't trigger it, and the required check is enforced by an enterprise ruleset that admin merge can't bypass).

Original commits and authorship by @armin-azar are preserved unchanged. Once this merges, #3910 will be closed as landed via this branch.

Validated earlier on manually-queued ADO build 1663620 (succeeded).


Original PR description (#3910):

Fix duplicate logging of MsalUiRequiredException

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Summary of the changes (Less than 80 chars)

Stop double-logging MsalUiRequiredException

Description

MsalUiRequiredException is already logged internally by MSAL.NET at error
level. Microsoft.Identity.Web additionally logged the same exception via
Logger.TokenAcquisitionError in two places in TokenAcquisition.cs, both
of which only rethrow/wrap the exception (no recovery logic depends on the
log call). This produced two log entries for a single MsalUiRequiredException,
as described in the issue.

This PR removes the redundant logging calls in those two catch blocks and
adds a comment explaining why nothing is logged there. All other
Logger.TokenAcquisitionError call sites (which handle exceptions MSAL does
not already log, e.g. certificate retry) are unchanged.

Added a unit test that reproduces the scenario from the issue (AcquireTokenSilent
called with no account/login hint, which MSAL throws MsalUiRequiredException for
synchronously) and asserts the log is not emitted.

Fixes #3528

@iarekk iarekk requested a review from a team as a code owner July 13, 2026 14:46
MsalUiRequiredException is already logged by MSAL.NET internally, so
re-logging it via Logger.TokenAcquisitionError in TokenAcquisition.cs
produced a duplicate log entry for every exception. Removed the
redundant logging in the two catch blocks that only rethrow/wrap the
exception.

Fixes #3528
@iarekk iarekk force-pushed the iarekk/pr-3910-duplicate-msaluirequired-log branch from 1ec99d2 to 04e8ab9 Compare July 13, 2026 15:37
@iarekk iarekk merged commit 69eae0c into master Jul 13, 2026
8 checks passed
@iarekk iarekk deleted the iarekk/pr-3910-duplicate-msaluirequired-log branch July 13, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicated logs of MsalUiRequiredException

3 participants